package com.cy.web;

import com.cy.bean.Classtab;
import com.cy.bean.Coach;
import com.cy.service.ClassTabService;
import com.cy.token.JwtUtil;
import com.cy.token.ResultResponse;
import com.cy.util.CacheRedisService;
import com.cy.util.PriceRange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class ClassTabController {
    @Autowired
    private ClassTabService classTabService;
    @Autowired
    private CacheRedisService cacheRedisService;

    @GetMapping("/getClassList")
    public ResultResponse getClassList(PriceRange priceRange){

        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setCode(20000);
        resultResponse.setMessage(JwtUtil.TOKEN_SUCCESS);
        resultResponse.setData(classTabService.getClassList(priceRange.getMinPrice(), priceRange.getMaxPrice()));
        return resultResponse;
    }

    @GetMapping("/deleteClass")
    public ResultResponse deleteClass(Classtab classtab,PriceRange priceRange){

        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setCode(20000);
        resultResponse.setMessage(JwtUtil.TOKEN_SUCCESS);
        if (classTabService.deleteClass(classtab)>0){
            resultResponse.setData(classTabService.getClassList(priceRange.getMinPrice(), priceRange.getMaxPrice()));
        }
        return resultResponse;
    }

    @PostMapping("/updateClass")
    public ResultResponse updateClass(@RequestBody Classtab classtab,PriceRange priceRange){

        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setCode(20000);
        resultResponse.setMessage(JwtUtil.TOKEN_SUCCESS);

        if (classTabService.updateClass(classtab)>0){
            resultResponse.setData(classTabService.getClassList(priceRange.getMinPrice(), priceRange.getMaxPrice()));
        }
        return resultResponse;
    }

    @PostMapping("/addClass")
    public ResultResponse addClass(@RequestBody Classtab classtab,PriceRange priceRange){

        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setCode(20000);
        resultResponse.setMessage(JwtUtil.TOKEN_SUCCESS);

        if (classTabService.addClass(classtab)>0){
            resultResponse.setData(classTabService.getClassList(priceRange.getMinPrice(), priceRange.getMaxPrice()));
        }
        return resultResponse;
    }
}
